package 第一个程序;

import java.io.IOException;
import java.net.*;

public class UDPClient {
    public static void main(String[] args) {

        DatagramSocket ds = null; //套接字
        DatagramPacket dp = null; // 数据包

        try {
            ds = new DatagramSocket();
            byte[] by = "hello,udp".getBytes();
            dp = new DatagramPacket(by,
                    0,
                    by.length,
                    InetAddress.getByName("127.0.0.1"),
                    10000);
            ds.send(dp);
        } catch (SocketException | UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (ds != null)
                ds.close();
        }
    }
}